IF exists(SELECT * FROM dbo.sysobjects WHERE name='vk_procent' AND xtype='P') 
BEGIN
	DROP PROCEDURE vk_procent
END
GO

CREATE   PROCEDURE vk_procent(
  @klas varchar(5),
  @periode char(2))
as
set nocount on

insert into vakrapportIndividueelBerekend(klas,vak,periode,
	inschrijvingsNr,code,cijfer) 
select vcr.klas,vcr.vak,vcr.periode,vcr.inschrijvingsNr,vcr.code, 
	convert(varchar(10),isnull(round(cijfer*100/maximum,0),-1))
from vakrapportIndividueleRekenwijze as vir
left join vakrapportCijferResultaten as vcr
	on vir.code = vcr.code
	and vir.klas = vcr.klas
	and vir.periode = vcr.periode
	and vir.code = vcr.code
where 	vir.rekenwijze = 'procent' and
	vir.klas like @klas and	vir.periode like @periode and
	cijfer >= 0 and	maximum > 0